<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>

<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 13, 2013
 */

    require('top.inc.php');
    $formLoad = new Form();
?>
<?php
if(isset($_SESSION['user'])) {
    if(isset($_POST['BugReport'])) {
        $query = "INSERT INTO bugreport ( title, description, userid, inserteddate ) VALUES ( :title, :description, :userid, :inserteddate )";
        $query_params = array(
            ':title' => $_POST['title'],
            ':description' => $_POST['description'],
            ':userid' => $_POST['userid'],
            ':inserteddate' => date('Y-m-d H:i:s')
        );
        
        try {
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        if($result) {
            echo $msg['38'];
        }
    } else {
?>
<form class="form-horizontal" action="" method="post" id="addBug">
    <div class="control-group">
        <label class="control-label" for="title"><?php echo $bugreport['title']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField("title", "span2", "title", $bugreport['title'], ""); ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="description"><?php echo $bugreport['description']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textArea1('description', 'span5', ''); ?>
        </div>
    </div>
    <input type="hidden" name="userid" value="<?php echo $_SESSION['user']['id']; ?>" />
    <div class="control-group">
        <label class="control-label" for="description">&nbsp;</label>
        <div class="controls">
            <input id="BugReport" class="btn btn-primary" type="submit" value="Report Bug" name="BugReport" />
        </div>
    </div>
    
    
</form>
<?php
    }
} else {
    header("Location: login.php");
}
    include ('bottom.inc.php');
?>

